package com.pi.pro.xcmg.am.common.vo.sys;

import org.springframework.http.HttpStatus;

/**
 * 调用webapi的响应对象
 * 
 * @author kris.liu
 * @param <T>
 *
 */
public class Result<T> {

	private ResultStatus status;
	private int code;
	private String message;
	private T data;

	public Result() {}
	
	public Result<T> success() {
		this.status = ResultStatus.success;
		this.code = HttpStatus.OK.value();
		return this;
	}
	
	public Result<T> fail() {
		this.status = ResultStatus.fail;
		this.code = HttpStatus.BAD_REQUEST.value();
		return this;
	}
	
	public Result<T> error() {
		this.status = ResultStatus.error;
		this.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
		return this;
	}

	public ResultStatus getStatus() {
		return status;
	}

	public String getMessage() {
		return message;
	}

	public Result<T> message(String message) {
		this.message = message;
		return this;
	}

	public int getCode() {
		return code;
	}

	public Result<T> code(int code) {
		this.code = code;
		return this;
	}

	public T getData() {
		return data;
	}

	public Result<T> data(T data) {
		this.data = data;
		return this;
	}
	
}
